# -*- mode: python; -*-

import os

Import('CfgmEnv')
env = CfgmEnv.Clone()

setup_sources = [
    'MANIFEST.in',
    'requirements.txt',
    'setup.py'
    ]

setup_sources_rules = []
for file in setup_sources:
    setup_sources_rules.append(
        env.Install(Dir('.'), "#controller/src/config/ironic-notification-manager/" + file))

setup_sources += env.SandeshGenPy(
    'ironic_notification_manager.sandesh',
    'ironic_notification_manager/sandesh/', False)

local_sources = [
        '__init__.py',
        'ironic_notification_manager.py',
        'ironic_kombu.py',
        ]

local_sources_rules = []
for file in local_sources:
    local_sources_rules.append(
        env.Install(Dir('ironic_notification_manager'),
                    "#controller/src/config/ironic-notification-manager/" + file))

sdist_depends = []
sdist_depends.extend(setup_sources_rules)
sdist_depends.extend(local_sources_rules)

cd_cmd = 'cd ' + Dir('.').path + ' && '
sdist_gen = env.Command('dist',
                         setup_sources + local_sources,
                         cd_cmd + 'python setup.py sdist')
env.Alias('controller/src/config/ironic-notification-manager:sdist', sdist_gen)
env.Depends(sdist_gen, sdist_depends)
env.Default(sdist_gen)

doc_files = []
doc_files += env.SandeshGenDoc('ironic_notification_manager.sandesh')
doc_files += env['CFGM_DOC_FILES']

if 'install_ironic_notification_manager' in BUILD_TARGETS:
    env.Alias('install_ironic_notification_manager',
              env.Command(None, setup_sources+local_sources,
                          cd_cmd + 'python setup.py install %s' %
                          env['PYTHON_INSTALL_OPT']))

env.Alias('install', env.Install(env['INSTALL_CONF'],
          'ironic-notification-manager.conf'))
env.Alias('install', env.InstallAs(env['INSTALL_SYSTEMD'] +
          '/ironic-notification-manager.service', 'systemd/ironic-notification-manager.service'))
env.Alias('install', env.Install(env['INSTALL_CONF'] +
          '/supervisord_config_files', 'ironic-notification-manager.ini'))
env.Alias('install', env.Install(
    env['INSTALL_MESSAGE_DOC'] + '/ironic-notification-manager/', doc_files))
